package Messages;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Serializable;

import Client.ClientDetails;

public class SendFileMsg implements Serializable ,Msg {

	private static final long serialVersionUID = 1L;
	byte[] file;
	String fileName;
	String fileCheckSum;
	String folderName;
	ClientDetails clientDetails;
	
	public SendFileMsg(String filePath, String fileCheckSum){//), ClientDetails cd) {
		System.out.println("send file = " + filePath +" "+fileCheckSum );
//		this.clientDetails = cd;
		this.fileCheckSum= fileCheckSum;
		this.file = null;
		File file = new File (filePath);
		int lastLocation = filePath.lastIndexOf("\\");
		String name = (String) filePath.subSequence(lastLocation+1,filePath.length());
		this.fileName = name;
	    FileInputStream fis;
		try {
			fis = new FileInputStream(file);
			BufferedInputStream bis = new BufferedInputStream(fis);
			byte[] fileBytes = new byte [(int)file.length()];
		    bis.read(fileBytes, 0, fileBytes.length);
		    this.file = fileBytes;
		    fis.close();
		    bis.close();		    
		} catch (FileNotFoundException e) {
	System.out.println("****************************");
	// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
	// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    
	    
	}
	@Override
	public MsgType getType() {
		// TODO Auto-generated method stub
		return MsgType.SEND_FILE;
	}
	public byte[] getFile() {
		return file;
	}
	public void setFile(byte[] file) {
		this.file = file;
	}
	public String getFileName() {
		return fileName;
	}
	public void setFileName(String fileName) {
		this.fileName = fileName;
	}
	public String getFileCheckSum() {
		return fileCheckSum;
	}
//	public ClientDetails getClientDetails() {
//		return clientDetails;
//	}
	public String getFolderName() {
		return folderName;
	}
	public ClientDetails getClientDetails() {
		return clientDetails;
	}
}
